package com.bright.hxj.cwduijie.service.impl;

import com.bright.hxj.cwduijie.enums.DataApi;
import com.bright.hxj.cwduijie.pojo.bo.ApiDataCollection;
import com.bright.hxj.cwduijie.pojo.po.ImmaterialAssets;
import com.bright.hxj.cwduijie.pojo.query.DuijieQuery;
import com.bright.hxj.cwduijie.repository.ImmaterialAssetsRepository;
import com.bright.hxj.cwduijie.service.AbstractPerThousandApiService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.function.Function;

/**
 * @Author hxj
 * @Date 2024/7/29 16:26
 * @Description
 */

@Component
@RequiredArgsConstructor
@Slf4j
public class ApiImmaterialAssetsServiceImpl extends AbstractPerThousandApiService<ImmaterialAssets> {

    private final ImmaterialAssetsRepository repo;

    @Override
    public JpaSpecificationExecutor getJpaSpecificationExecutor() {
        return repo;
    }

    @Override
    public DataApi getDataApi() {
        return DataApi.IMMATERIAL_ASSETS;
    }

    @Override
    public Function<ImmaterialAssets, Integer> getIdFunc() {
        return ImmaterialAssets::getID;
    }

    @Override
    public Function<ImmaterialAssets, String> getDataKeyFunc() {
        return ImmaterialAssets::getDATA_KEY;
    }

    @Override
    public Function<ApiDataCollection, List<ImmaterialAssets>> getDataFunc() {
        return ApiDataCollection::getImmaterialAssets;
    }

    @Override
    public DataApi getDeleteDataApi() {
        return DataApi.DELETE_IMMATERIAL_ASSETS;
    }


    @Override
    protected void getData(ApiDataCollection apiDataCollection, DuijieQuery duijieQuery) {
//        List<ImmaterialAssets> assets = repo.findAll(getDataQuerySpecification(OpType.ADD_OR_EDIT.getValue(), duijieQuery.getCreditCode()));
        apiDataCollection.setImmaterialAssets(getNeedDuijieData(duijieQuery));
    }

//    @Override
//    protected List<ImmaterialAssets> getNeedDeleteData(DuijieQuery duijieQuery) {
//        return repo.findAll(getDataQuerySpecification(OpType.DEL.getValue(), duijieQuery.getCreditCode()));
//    }
}
